package com.thkj.service.impl;

import com.thkj.entity.TblCameraRele;
import com.thkj.service.TblMoniConfigService;
import dp.dao.PagingList;
import com.thkj.framework.base.BaseService;
import com.thkj.service.TblIndividualService;
import com.thkj.entity.TblIndividual;

import java.util.List;
import java.util.Map;

import dp.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TblIndividualServiceImpl extends BaseService implements TblIndividualService {
    @Autowired
    private TblMoniConfigService tblMoniConfigService;

    public void insertTblIndividual(TblIndividual t) {
        dao.insert("com.thkj.mapper.TblIndividual.insert", t);
    }

    public Integer updateTblIndividual(TblIndividual t) {
        t.setUpdateTime(DateUtil.getNowAsTimestamp());
        int row = dao.update("com.thkj.mapper.TblIndividual.update", t);
        return row;
    }

    @Override
    public Integer updateCameraId(TblIndividual t) {
        int row = dao.update("com.thkj.mapper.TblIndividual.updateCameraId", t);
        return row;
    }

    @Override
    public Integer updateState(Map<String, String> param) {
        int row = dao.update("com.thkj.mapper.TblIndividual.updateState", param);
        return row;
    }

    public Integer deleteTblIndividual(String t) {
        return dao.update("com.thkj.mapper.TblIndividual.delete", t);
    }

    public TblIndividual getTblIndividualById(String t) {
        return dao.queryForObject("com.thkj.mapper.TblIndividual.getById", t, TblIndividual.class);
    }

    @Override
    public PagingList<Map> query(int pageIndex, int pageSize, Map<String, Object> param) {
        PagingList<Map> mapPagingList = dao.queryForPagingList("com.thkj.mapper.TblIndividual.query", param, pageIndex, pageSize, Map.class);

        List<Map> list = mapPagingList.getList();

        for (Map map : list) {
            String cameraId = (String) map.get("cameraId");
            TblCameraRele tblCameraRele = null;
            if (StringUtils.isNotBlank(cameraId)) {
                tblCameraRele = tblMoniConfigService.getById(cameraId);
            }
            map.put("bindCamera", tblCameraRele);
        }
        return mapPagingList;
    }

    @Override
    public Integer count() {
        return dao.queryForObject("com.thkj.mapper.TblIndividual.count", "", Integer.class);
    }

    @Override
    public List<Map> queryNoPage(Map<String, Object> param) {
        List<Map> maps = dao.queryForList("com.thkj.mapper.TblIndividual.query", param, Map.class);
        return maps;
    }

}